package ru.averta.notes.service.impl;

import java.io.Serializable;
import java.util.Collection;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;

import ru.averta.notes.dao.UserableDao;
import ru.averta.notes.domain.User;
import ru.averta.notes.domain.abstr.BusinessObject;
import ru.averta.notes.domain.flags.IUserable;
import ru.averta.notes.service.UserableObjectService;
import ru.averta.notes.service.security.SecurityService;

@Transactional
public abstract class UserableBusinessObjectService<T extends IUserable & BusinessObject, PK extends Serializable, D extends UserableDao<T, PK>> extends GenericBusinessObjectService<T, PK, D> implements
        UserableObjectService<T, PK> {

    @Autowired
    SecurityService security;
    
    Logger logger = LoggerFactory.getLogger(UserableBusinessObjectService.class);

    public Collection<T> findByUser(User user) {
        return dao.findByUser(user);
    }

    @Override
    public Collection<T> findByCUser() {
        return dao.findByUser(getCurrentUser());
    }

    protected User getCurrentUser() {
        return security.getCurrentUser();
    }
}
